import { _decorator, Component, director, Label, Node, ProgressBar, Slider, tween, UITransform } from 'cc';
const { ccclass, property } = _decorator;

enum LoadingState {
    NONE,
    LOADING,
    LOADED,
}


@ccclass('Loading')
export class Loading extends Component {

    loadStats:LoadingState

    @property(Label) loading_text: Label = null;
    @property(ProgressBar) loading: ProgressBar = null;

    start() {
        // let progress=this.loading.getComponent(ProgressBar)
        let progress=this.loading.getComponent(ProgressBar)
        let time = 0;
        tween(progress)
        .delay(3)
        .to(10,{},{
            onUpdate:(target:Slider,ratio)=>{
                console.log("ratio",target)
                progress.progress +=0.1
                this.loading_text.string=progress.progress*100+"%"
            }
        })
        .start();


    }

    loadScene(name:string){
        if(this.loadStats==LoadingState.LOADING){
            return
        }
        this.loadStats=LoadingState.LOADING
        director.loadScene(name,()=>{
            this.loadStats=LoadingState.LOADED
        })
    }

    update(deltaTime: number) {
        
    }
}


